<?php

use yii\db\Migration;

class m171123_075155_alter_goods_price extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%goods_price}}', 'is_activity', $this->smallInteger(1)->defaultValue(0)->comment('是否时活动 0 否 1是'));
            $this->addColumn('{{%goods_price}}', 'activity_start_time', $this->integer()->defaultValue(0)->comment('活动开始时间'));
            $this->addColumn('{{%goods_price}}', 'activity_end_time', $this->integer()->defaultValue(0)->comment('活动结束时间'));
            $this->addColumn('{{%goods_price}}', 'effective_number', $this->smallInteger(4)->defaultValue(0)->comment('有效人数'));
        }

    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%goods_price}}', 'is_activity');
            $this->dropColumn('{{%goods_price}}', 'activity_start_time');
            $this->dropColumn('{{%goods_price}}', 'activity_end_time');
            $this->dropColumn('{{%goods_price}}', 'effective_number');
        }
    }
}
